import {produce} from 'immer';
import * as types from '@/redux/constant'
import { globalStateType } from '@/redux/interface/index'

const init:globalStateType = {
   token:'',
   userInfo:{},
   isGuid:false,
}

// global reducer
const global = (preState: globalStateType = init, action: any) =>produce(preState,draftState=>{
   let {type,data} = action
   switch (type) {
       case types.SET_TOKEN:
           draftState.token = data
           break;

       case types.SET_USERINFO:
           draftState.userInfo = {...data}
           break;

       case types.SET_IS_GUID:
         draftState.isGuid = data
         break;

       default:
           return draftState;
   }

})

export default global;


